//ES5 类的创建

// function Person(name, age) {
//   this.name = name
//   this.age = age
// }
// Person.prototype.sayHi = function () {
//   console.log('hi', this.name)
// }

// Person.country = "China" //静态属性

// //寄生组合式继承
// function Student(name, age) {
//   this.grade = grade
//   Person.apply(this, arguments) //子类继承父类的属性
// }

// //Student.prototype = new Person()//继承内容过多

// function inheritPrototype(Student, Person) {
//   function F() {}

//   F.prototype = Person.prototype
//   Student.prototype = new F()
//   Student.prototype.constructor = Student
// }

// inheritPrototype(Student, Person)

//Es6 类的创建
class Person { //外面是类名
  constructor(name, age) {

    //构造函数
    this.name = name
    this.age = age
  }
  sayHi() { //放在原型上的
    console.log('hi', this.name)
  }
}

//实例化
let p1 = new Person("lucy", 18)
p1.sayHi
console.dir(p1)

//ES6继承
class Student extends Person {
  city = "成都" //ES7语法,等价与写在constructor中
  constructor(name, age, grade) {
    super(name, age) //必须在子类constructor中先调用super实现继承'
    this.grade = grade
  }
  static country = 'China' //静态属性
  static run() { //静态方法
    console.log("run")
  }

  get sex() { //获取sex属性的时候会触发该函数
    console.log("获取性别")
    return "女"

  }
  set sex(newVal) { //设置该属性的时候会触发该属性
    console.log("设置性别", newVal)
  }
}
//实例化子类
let s1 = new Student("lily", 18, "高三")
s1.sayHi()
console.dir(s1)

console.log(Student.country) //静态的调用
Student.run

console.log(s1.sex)
s1.sex = "男"

//涵盖class的构造函数、原型、静态属性、以及最新写法 
class Cat {
  static instance = null
  //以下几个写法都是实例属性
  city = '成都'

  constructor(name) {
    this.name = name
  }

  sayBye = function () {//看谁调用的
    console.log('Bye')
  }

  run = () => {//考虑this指向
    console.log('run')
  }

  say() { //原型上的方法
    console.log("喵喵")
  }
}

const c = new Cat('花花')
console.log(c)